package designMode.trategy;

import java.util.ArrayList;
import java.util.List;

//�̳�����Ʒ�Ĵ��۲���
public class Sell {
	public static void main(String[] args) {
		Goods apple = new Goods("ƻ��", 20);
		Goods orange = new Goods("����", 30);
		Market market = new Market();
		market.goodss.add(apple);
		market.goodss.add(orange);
		// ԭ�۳���0����Ʒ
		market.sell(0);
		// ��Traegy01�Ĳ��Գ���1����Ʒ
		market.sell(1, new Traegy02());
	}
}

//�̳���
class Market {
	// ��Ʒ�б�
	List<Goods> goodss = new ArrayList<Goods>();

	// ԭ�۳���
	public void sell(int i) {
		Goods goods = goodss.get(i);
		System.out.println(goods.name + "ԭ��" + goods.price + "Ԫһ��");
	}

	// ���۳��ۣ���Ҫ������۲���
	public void sell(int i, SellTraegy st) {
		Goods goods = goodss.get(i);
		System.out.println(st.title() + ":" + goods.name + "��" + st.dazhe(goods.price) + "Ԫһ��");
	}
}

//��Ʒ��
class Goods {
	String name;
	double price;

	public Goods(String name, double price) {
		this.name = name;
		this.price = price;
	}
}

//���Խӿ�
interface SellTraegy {
	String title();

	double dazhe(double price);
}

//�Զ�����²���
class Traegy01 implements SellTraegy {
	@Override
	public double dazhe(double price) {
		return price * 0.9;
	}

	@Override
	public String title() {
		return "��Ʒ���۴���";
	}
}

//�Զ�����²���
class Traegy02 implements SellTraegy {
	@Override
	public double dazhe(double price) {
		return price * 0.5;
	}

	@Override
	public String title() {
		return "��ְ�۴���";
	}
}
